package com.shen.JUC.callab;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //适配类
        FutureTask task = new FutureTask(new Thread1());

        new Thread(task).start();
        new Thread(task).start();//结果会被缓存，效率高
        String o = (String) task.get();//返回结果,可能会产生阻塞
        System.out.println(o);
    }
}

class Thread1 implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println("callable启动");
        return "123";
    }
}